package com.juitar.base.enumerator;

import com.juitar.base.Chord;
import com.juitar.base.Tuning;
import com.juitar.base.utils.IntBitMask;

public class BitFretEnumeratorFactory implements IFingeringEnumeratorFactory {

    public FingeringEnumerator create(Chord chord, Tuning tuning) {
        int[] open = tuning.getOpenStringNotes();
        IFretEnumerator[] fretEnums = new IFretEnumerator[open.length];
        for (int i = 0; i < open.length; i++) {
            int mask = 0;
            // if (chord.contains(open[i]) == 0) {
            mask = 1; // muted string
            // }
            for (int j = 0; j < 12; j++) {
                int current = open[i] + j;
                int contains = chord.contains(current);
                if (contains > 0) {
                    mask = IntBitMask.set(mask, j + 1);
                }
            }
            fretEnums[i] = new BitFretEnumerator(mask);
        }
        return new FingeringEnumerator(fretEnums);
    }

}
